package com.aoip.telemetry.telemetry.configureui.business.commonconfig.waga.service.impl;

import com.aoip.telemetry.telemetry.entity.waga.WagaDefinitionEntity;
import com.aoip.telemetry.telemetry.configureui.business.commonconfig.waga.mapper.WagaDefinitionMapper;
import com.aoip.telemetry.telemetry.configureui.business.commonconfig.waga.service.WagaDefinitionService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author chenbai
 * @version 1.0
 * @date 2022/4/24 23:20
 */
@Service
@DS("telemetry")
public class WagaDefinitionServiceImpl implements WagaDefinitionService {
    @Resource
    private WagaDefinitionMapper mapper;

    @Override
    public List<WagaDefinitionEntity> list(WagaDefinitionEntity entity) {
        QueryWrapper<WagaDefinitionEntity> queryWrapper = new QueryWrapper<>();
        String wagaName = entity.getWagaName();
        if (StringUtils.hasText(wagaName)) {
            queryWrapper.like(true, "waga_name", wagaName);
        }
        long factoryStationId = entity.getFactoryStationId();
        if (factoryStationId > 0) {
            queryWrapper.eq(true, "factory_station_id", factoryStationId);
        }
        String wagaType = entity.getWagaType();
        if (StringUtils.hasText(wagaType)) {
            queryWrapper.eq(true, "waga_type", wagaType);
        }
        String wagaOpenType = entity.getWagaOpenType();
        if (StringUtils.hasText(wagaOpenType)) {
            queryWrapper.eq(true, "waga_open_type", wagaOpenType);
        }
        return mapper.selectList(queryWrapper);
    }

    @Override
    public WagaDefinitionEntity detail(String id) {
        return mapper.selectById(id);
    }

    @Override
    public int insert(WagaDefinitionEntity entity) {
        return mapper.insert(entity);
    }

    @Override
    public int update(WagaDefinitionEntity entity) {
        return mapper.updateById(entity);
    }

    @Override
    public int initCache() {
        return 0;
    }

    @Override
    public void delete(Long[] ids) {
        mapper.deleteBatchIds(Arrays.asList(ids));
    }
}
